package temaihui.daimaitemai;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

import org.json.JSONObject;

import java.io.Console;

import cz.msebera.android.httpclient.Header;

public class MainActivity extends FragmentActivity implements View.OnClickListener {

    private HomeFragment homeFragment = HomeFragment.newInstance(null,null);
    private DiscoverFragment discoverFragment = DiscoverFragment.newInstance(null,null);
    // 定义布局对象
    private FrameLayout homeFrame, mineFrame, cartFrame, findFrame;
    private View homeTopMenu;
    // 定义图片组件对象
    private ImageView homeIv, mineIv, cartIv, findIv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        clickHomeBtn();
    }

    private void initView(){
        homeFrame = (FrameLayout)findViewById(R.id.layout_home);
        findFrame = (FrameLayout)findViewById(R.id.layout_find);
        homeFrame.setOnClickListener(this);
        findFrame.setOnClickListener(this);

        homeIv = (ImageView)findViewById(R.id.image_home);
        findIv = (ImageView)findViewById(R.id.image_find);
        homeTopMenu = findViewById(R.id.home_top_menu);
    }
    @Override
    protected void onStart() {
        super.onStart();

    }
    @Override
    protected void onResume() {
        super.onResume();

    }
    private void clickHomeBtn(){
        homeTopMenu.setVisibility(View.VISIBLE);

        homeIv.setImageResource(R.drawable.tab_home_on);
        findIv.setImageResource(R.drawable.tab_find_off);

        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_content, homeFragment);
        // 事务管理提交
        fragmentTransaction.commit();


    }
    private void clickFindBtn(){
        homeTopMenu.setVisibility(View.GONE);
        homeIv.setImageResource(R.drawable.tab_home_off);

        findIv.setImageResource(R.drawable.tab_find_on);
        // 得到Fragment事务管理器
        FragmentTransaction fragmentTransaction = this
                .getSupportFragmentManager().beginTransaction();
        // 替换当前的页面
        fragmentTransaction.replace(R.id.frame_content, discoverFragment);
        // 事务管理提交
        fragmentTransaction.commit();

    }
    private void clickCartBtn(){

    }

    private void clickMineBtn(){

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_home:
                clickHomeBtn();
                break;
            case R.id.layout_find:
                clickFindBtn();
                break;
            case R.id.layout_cart:
                clickCartBtn();
                break;
            case R.id.layout_mine:
                clickMineBtn();
                break;

        }
    }

}
